package com.monitor.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.monitor.entity.ErpDriver;
import com.monitor.entity.ErpDriverRepair;
import com.monitor.entity.ErpUser;
import com.monitor.service.ErpDriverRepairService;
import com.monitor.service.ErpDriverService;
import com.monitor.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 车务管理表 前端控制器
 * </p>
 *
 * @author LX
 * @since 2018-09-13
 */
@RestController
@RequestMapping("/erpDriverRepair")
@Transactional
@Api(description="车务管理")
public class ErpDriverRepairController {

    @Resource
    private ErpDriverService driverService;
    @Resource
    private ErpDriverRepairService driverRepairService;

    @RequestMapping("/inertOrUpdateRepair")
    @ApiOperation("添加Or修改车务信息")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "custId", value = "客户ID", required = false, dataType = "int", paramType = "query")*/
    })
    public @ResponseBody
    Result<Integer> inertOrUpdateRepair(ErpDriverRepair driverRepair) {
        Result<Integer>  result=new Result<Integer>();
        try{
        	List<ErpDriverRepair> dr=driverRepairService.selectList(new EntityWrapper<ErpDriverRepair>().eq("pid", driverRepair.getPid()));
        	if(dr.size()>0) {
        		driverRepair.setId(dr.get(0).getId());
        	}
            result.setCount(1);
            result.setData(driverRepairService.insertOrUpdate(driverRepair)?1:0);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

    @RequestMapping("/getdriverRepair")
    @ApiOperation("获取车务信息")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "custId", value = "客户ID", required = false, dataType = "int", paramType = "query")*/
    })
    public @ResponseBody
    Result<List<ErpDriverRepair>> getdriverRepair() {
        Result<List<ErpDriverRepair>> result=new Result<List<ErpDriverRepair>>();
        try{
            List<ErpDriverRepair> customerCar=driverRepairService.selectList(new EntityWrapper<ErpDriverRepair>());
            result.setCount(1);
            result.setData(customerCar);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }


    @RequestMapping("/getdriverRepairByPid")
    @ApiOperation("根据Pid获取车务信息")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "pid", value = "pid(我也没搞懂是啥)", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
    Result<List<ErpDriverRepair>> getdriverRepairByPid(Integer pid) {
        Result<List<ErpDriverRepair>> result=new Result<List<ErpDriverRepair>>();
        try{
            List<ErpDriverRepair> customerCar=driverRepairService.selectList(new EntityWrapper<ErpDriverRepair>().eq("pid",pid));
            result.setCount(1);
            result.setData(customerCar);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }

    @RequestMapping("/removedriverRepairById")
    @ApiOperation("根据id删除车务信息")
    @ApiImplicitParams({
           /* @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "部门名称", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "parentId", value = "父id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "customerCode", value = "客户编号", required = false, dataType = "int", paramType = "query"),*/
            @ApiImplicitParam(name = "Id", value = "Id", required = false, dataType = "int", paramType = "query")
    })
    public @ResponseBody
    Result<Integer> removedriverRepairById(Integer Id) {
        Result<Integer> result=new Result<Integer>();
        try{
            result.setCount(1);
            result.setData(driverRepairService.deleteById(Id)?1:0);
        }catch (Exception e){e.printStackTrace();}
        return result;
    }


}

